import jmespath

from config_params.base_util import baseUtil


class Timer:

    def __init__(self, data):
        self.data = data

    def jme_path(self, exp):
        return jmespath.search(exp, self.data)

    def ConstantTimer(self, class_name):
        constant_timer_dict = {}
        constant_timer_dict["name"] = self.jme_path("name") if self.jme_path("name") is not None else "Constant Timer"
        constant_timer_dict["delay"] = self.jme_path("delay") if self.jme_path("delay") is not None else 300
        constant_timer_dict["comments"] = self.jme_path("comments") if self.jme_path("comments") is not None else ""
        constant_timer_dict["is_enabled"] = self.jme_path("is_enabled") if self.jme_path("is_enabled") is not None else True
        constant_timer_obj = baseUtil.create_instance(class_name, constant_timer_dict)
        return constant_timer_obj

    def timer(self):
        timer_list = []
        if self.jme_path("type") == "ConstantTimer":
            timer_list.append(self.ConstantTimer(self.jme_path("type")))
        return timer_list
